﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace AI.Steering
{
    /// <summary>
    /// 拦截
    /// </summary>
    public class SteeringForIntercept : Steering
    {
        [Tooltip("目标物体变换组件")]
        public Transform targetTF;
        public override Vector3 GetForce()
        {
            Vector3 targetVolecity = targetTF.GetComponent<Locomotion>().currentForce;
            //时间：路程/速度
            float time = Vector3.Distance(transform.position, targetTF.position) / (controller.currentForce.magnitude + targetVolecity.magnitude);
            //拦截距离：时间*速度
            Vector3 moveDistanceVector = time * targetVolecity;
            //拦截点：目标位置
            Vector3 targetPoint = targetPos = targetTF.position + moveDistanceVector;//Vector3 targetPoint = targetPos = targetTF.position + moveDistanceVector;
            //期望力 = 目标点 - 自身点
            Vector3 expectForce = (targetPoint - transform.position).normalized * speed;
            //实际力 = 期望力 - 当前力
            return (expectForce - controller.currentForce) * weight;//权重越大，实际力到达最大越快
        }
        //以下测试，可删除
        private Vector3 targetPos;
        private void Update()
        {
            Debug.DrawLine(transform.position,targetPos);
        }
    }
}

